<?php

if (!defined('IN_ANWSION'))
{
	die;
}

class main extends AWS_CONTROLLER 
{
	public static $m_arrStatus = array('0' => '运营中','1' => '停止服务');
	public function get_access_rule()
	{
		$rule_action['rule_type'] = 'white'; //黑名单,黑名单中的检查  'white'白名单,白名单以外的检查
		
		if ($this->user_info['permission']['visit_question'] AND $this->user_info['permission']['visit_site'])
		{
			$rule_action['actions'] = array(
				'index',
				'explore'	
			);
		}
		
		return $rule_action;
	}

	public function setup()
	{
		$this->crumb('专辑', '/special/');
	}
	public function index_action()
	{
		
// 		if (! $this->user_id)
// 		{
// 			$this->explore_action();
// 			exit;
// 		}
		//边栏可能感兴趣的人
		if (TPL::is_output('block/sidebar_recommend_users_topics.tpl.htm', 'special/explore'))
		{
			$recommend_users_topics = $this->model('module')->recommend_users_topics($this->user_id);
			TPL::assign('sidebar_recommend_users_topics', $recommend_users_topics);
		}
		//边栏热门用户
		if (TPL::is_output('block/sidebar_hot_users.tpl.htm', 'special/explore'))
		{
			$sidebar_hot_users = $this->model('module')->sidebar_hot_users($this->user_id, 5);
			
			TPL::assign('sidebar_hot_users', $sidebar_hot_users);
		}
		//边栏热门标签
		if (TPL::is_output('block/sidebar_hot_topics.tpl.htm', 'special/explore'))
		{
			$sidebar_hot_topics = $this->model('module')->sidebar_hot_topics($this->user_id, $_GET['category']);
			
			TPL::assign('sidebar_hot_topics', $sidebar_hot_topics);
		}
		
		//边栏专题
		if (TPL::is_output('block/sidebar_feature.tpl.htm', 'special/explore'))
		{
			$feature_list = $this->model('module')->feature_list();
			
			TPL::assign('feature_list', $feature_list);
		}
		
		// 专辑
		
		$special_list = array();
		
		$special_list = $this->model('special')->get_special_list($_GET['page'], get_setting('contents_per_page'));
		foreach ($special_list as $k =>$special)
		{
			$special_list[$k]['date'] = date('Y-m-d',$special['add_time']);
			$special_list[$k]['url'] = 'special/explore/'.$special['id'];
		}
		
		TPL::assign('special_list', $special_list);
		TPL::assign('special_list_bit', TPL::output('special/ajax/special_list', false));
		
		TPL::import_css('css/main.css');
		TPL::import_js('js/explore.js');
		
		TPL::output("special/index");
	}
	
	public function explore_action()
	{
		if (!$_GET[id])
		{
			return false;
		}
		
		$special_id = $_GET['id'];
		
		// 专辑  站点列表 信息
	
		$special_question_list = $this->model('special')->get_special_question_list_by_special_id($special_id);
		
		
		$question_ids = array();
		$question_score = array();
		$question_comment = array();
		foreach ($special_question_list as $k =>$v)
		{
			$question_ids[$v['question_id']] = $v['question_id'];
			$question_score[$v['question_id']] = $v['score'];
			$question_comment[$v['question_id']] = $v['comment'];
			$question_qsid[$v['question_id']] = $v['id'];
		}
		$question_info_list = $this->model('question')->get_question_info_by_ids($question_ids);
		
		TPL::assign('question_qsid', $question_qsid);
		TPL::assign('question_score', $question_score);
		TPL::assign('question_comment', $question_comment);
		TPL::assign('question_info_list', $question_info_list);
		
		// 专辑信息
		$special_info = $this->model('special')->get_special_info_by_id($special_id);
		
		TPL::assign('special_info', $special_info);
		
		// 发现专辑  随即机制
		
		$special_list_new = $this->model('special')->get_special_list(0,5,true);
		
		foreach ($special_list_new as $k => $new)
		{
			if ($new['id'] == $special_id)
			{
				unset($special_list_new[$k]);
			}
		}
		// 评分插件
		TPL::import_js('js/jraty/js/jquery.raty.js');
		TPL::import_js('js/jraty/js/jquery.raty.min.js');
		//自动完成
		TPL::import_js(array(
				'admin/js/jquery.autocomplete.js',
		));
		TPL::import_css('js/jquery.autocomplete.css');
		
		TPL::assign('special_list_rand', $special_list_new);
		
		
		
		TPL::import_css('css/main.css');

		
		TPL::output("special/special_question_list");
	}
}